<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/article/ShowEdit.class.php
 *
 * 显示编辑文章的界面
 *
 * PHP Version 5
 *
 * @package:   class.article
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: ShowEdit.class.php,v 1.1 2006-09-24 14:38:33 ghw Exp $
 * @date:      $Date: 2006-09-24 14:38:33 $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

//包含我们需要的工具软件包
include_once CLASS_PATH.'article/CategoryUtil.class.php';
include_once CLASS_PATH.'article/ArticleUtil.class.php';
include_once FUNCTION_PATH.'getCurrentDate.fun.php';
include_once FUNCTION_PATH.'getIp.fun.php';

include_once LIB_PATH.'fckeditor/fckeditor.php';



class ShowEdit extends BaseAction {

   /**
    * 数据库的连接
    */
   private $db;

   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }


   /**
    * 显示编辑文章的界面
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {

      //取得要编辑的文章的id
      $id = $this->getParameterFromGET('id');

      if ( !$id  ) {
         $this->AlertAndBack("没有指定要编辑的文章");
         return;
      }
 
      //看看文章是否存在
      
      if ( !ArticleUtil::isExists($this->db, $id)) {
         $this->AlertAndBack("要编辑的文章不存在");
         return;
      }

      //看看文章的编辑提交者是不是现在正在登录的用户。
      $user_name = $_SESSION['user']['name'];

      //取得文章的信息
      $article_info = ArticleUtil::getArticleInfor($this->db, $id);

      
      if ( $article_info['submitUser'] != $user_name ) {
         $this->AlertAndBack('只有文章的提交者才能编辑文章');
         return;
      }


      $smarty = $this->getSmarty();

      //显示头
      $categroy = CategoryUtil::getTopCategory($this->db);
      $smarty->assign('catagroy', $categroy);

      //设置SEO的头
      $smarty->assign('clone_title', '编辑文章'.$article_info['title'].'/5anet.com' );
      $smarty->assign('header_meta_content','编辑文章/5anet.com' );

      //设置文章id
      $smarty->assign('article_id', $id);
      $smarty->assign('title', $article_info['title']);
      $smarty->assign('author', $article_info['author']);
      $smarty->assign('fromaddr', $article_info['fromaddr']);

      //取得所有的分类
      $all_catagory = CategoryUtil::getAllCatagoryInfo($this->db);

      $options = "";

      foreach ( $all_catagory as $lp ) {
         $options .= "<option value=".$lp['id'];

         if ( $lp['id'] == $article_info['type'] ) {
            $options .= ' selected ';
         }

         $options .= '>'.$lp['name'].'</option>'."\n";
      }

      $smarty->assign('options', $options);




      $fck = new FCKeditor('content');
      $fck->BasePath = FCKEDITOR_BASEPATH;
      $fck->Value = $article_info['content'];
      $smarty->assign('fck', $fck);

      $smarty->display('showeditarticle.tmpl');


   }
}

?>
